package com.buttonpay.home;

import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.graphics.LinearGradient;
import android.os.Handler;
import android.text.InputType;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.Spinner;
import android.widget.TextView;

import com.buttonpay.R;

public class UtilityDialog extends Dialog implements android.view.View.OnClickListener 
{

	Button btnOk,btnCancel,btnOkConfirmation,btnCancelConfirmation;
	EditText etMobileNo,etAmount,etSecurePin,etReferenceMobileNo;
	Context context;
	String mobileNo="",amount="",securePin="";
	Button btnOkSummary,btnContinue;
	String operatorName;
	Spinner spAmount;
	
	TextView tvOperatorname,tvDialogHeader;
	TextView tvReferenceMobileNo;
	LinearLayout dialoglayout;
	private Handler myhandler=new Handler();
	private ProgressDialog pd=null;
	
	public UtilityDialog(Context context, String operatoName)
	{
		super(context);
		this.context=context;
		this.operatorName= operatoName;
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(com.buttonpay.R.layout.topup_dialog);
//		getWindow().setFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND,WindowManager.LayoutParams.FLAG_BLUR_BEHIND);

		
		btnOk=(Button)findViewById(R.id.btn_ok);
		spAmount=(Spinner)findViewById(R.id.spAmount);
		btnCancel=(Button)findViewById(R.id.btn_Cancel);
	 	etMobileNo=(EditText)findViewById(R.id.etRefMobileNo);
	 	etAmount=(EditText)findViewById(R.id.etAmount);
	 	etSecurePin=(EditText)findViewById(R.id.etSecurePin);
		spAmount=(Spinner)findViewById(R.id.spAmount);
		tvOperatorname=(TextView)findViewById(R.id.tvOperatorName);
		
		tvDialogHeader=(TextView)findViewById(R.id.dialog_header);
		
		dialoglayout=(LinearLayout)findViewById(R.id.layout_dialog);
		
		etReferenceMobileNo=new EditText(getContext());
		tvReferenceMobileNo=new TextView(getContext());
		tvReferenceMobileNo.setText("Enter Reference Mobile Number");
		etReferenceMobileNo.setSingleLine(true);
		
		etReferenceMobileNo.setInputType(InputType.TYPE_CLASS_NUMBER);
		
		dialoglayout.addView(tvReferenceMobileNo, 8);
		dialoglayout.addView(etReferenceMobileNo,9);
		tvDialogHeader.setText("Data Recharge");
		tvOperatorname.setText(operatoName);
	 	
		btnOk.setOnClickListener(this);
		btnCancel.setOnClickListener(this);
		
		spAmount.setVisibility(Spinner.GONE);
		 
		 
	 }
	public void onClick(View v) 
	{
		/** When OK Button is clicked, dismiss the dialog */
		if (v == btnOk)
		{
			
			dismiss();
			mobileNo=etMobileNo.getText().toString();
			amount=etAmount.getText().toString();
			securePin=etSecurePin.getText().toString();
			
			setContentView(R.layout.confirmation_layout);
			TextView tvConfirmationText=(TextView)findViewById(R.id.tvConfirmationText);
			
			tvConfirmationText.setText("Please Confirm Data Recharge of Airtel ,Number 9825412323 with amount TZS10.");
			

			btnOkConfirmation=(Button)findViewById(R.id.btn_Ok_confirmation);
			btnCancelConfirmation=(Button)findViewById(R.id.btn_Continue_confirmation);
		
			btnOkConfirmation.setOnClickListener(this);
			btnCancelConfirmation.setOnClickListener(this);
			show();

			
		}
		else if(v==btnOkConfirmation)
		{
			dismiss();
			setContentView(R.layout.top_up_summary);
			TextView tvSummaryText=(TextView)findViewById(R.id.tvSummaryText);
			
			btnOkSummary=(Button)findViewById(R.id.btn_Ok_Summary);
			btnContinue=(Button)findViewById(R.id.btn_Continue);
			btnOkSummary.setOnClickListener(this);
			btnContinue.setOnClickListener(this);
			
			tvSummaryText.setText("Thank you For using Utility pay Data Recharge Service. " +
					"Mobile Number 9825412323 is successfully Recharged up with TZS10." +
					" Your Account balance is  TZS100. Unique Transaction ID is ADUSY1823.");
			 pd=ProgressDialog.show(context,    
					 null,"Please Wait..." , true);
			 
			 new Thread(new Runnable() 
		        {
		            public void run() 
		            {
		            	try 
		            	{
							Thread.sleep(2000);
							
						} catch (InterruptedException e)
						{
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
		            	
		            	myhandler.post(new Runnable() 
			            {
			                    public void run() 
			                    {
			                    	
			                   	    pd.dismiss();
			                   	    show();
			                    }
			                });
			            }    
			 
			        }).start();  
				
			
		}
		else if(v==btnCancelConfirmation)

		{
			dismiss();
		}
		else if(v==btnOkSummary)
		{
			dismiss();
		}
		else if(v==btnContinue)
		{
			dismiss();
			new UtilityDialog(context, operatorName).show();
		}
		else if(v==btnCancel)
		{
			dismiss();
		}
		
		
		
	}
	

}
